#include <iostream>
#include <sw/redis++/redis++.h>

int main() {
    // g++ redis_example.cc -lredis++ -lhiredis -pthread
    try {
        sw::redis::Redis redis("tcp://localhost:6379");

        // 设置键值对
        redis.set("mykey", "Hello, RedisPlusPlus!");

        // 获取键的值
        auto value = redis.get("mykey");
        if (value) {
            std::cout << "Value of 'mykey': " << value.value() << std::endl;
        } else {
            std::cout << "Failed to get value of 'mykey'" << std::endl;
        }
    } catch (const std::exception& ex) {
        std::cerr << "Exception occurred: " << ex.what() << std::endl;
    }

    return 0;
}
